package com.cy.pj.eiems.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cy.pj.eiems.Exception.ServiceException;
import com.cy.pj.eiems.dao.EiemsAgencyInformationDao;
import com.cy.pj.eiems.entity.EiemsAgencyInformation;
import com.cy.pj.eiems.service.EiemsAgencyInformationService;
import com.cy.pj.eiems.vo.PageObject;

@Service
public class EiemsAgencyInformationServiceImpl implements EiemsAgencyInformationService{

	@Autowired
	private EiemsAgencyInformationDao eiemsAgencyInformationDao;

	@Override
	public PageObject<EiemsAgencyInformation> findObjects(
			String name, Integer pageCurrent) {

		if(pageCurrent==null||pageCurrent<1)
			throw new IllegalArgumentException("当前页码值不正确");
		//2.基于用户名查询总记录数并进行校验
		int rowCount=eiemsAgencyInformationDao.getRowCount(name);
		if(rowCount==0)
			throw new ServiceException("记录不存在");
		//3.查询当前页记录
		Integer pageSize=10;
		Integer startIndex=(pageCurrent-1)*pageSize;
		List<EiemsAgencyInformation> records=
				eiemsAgencyInformationDao.findObjects(name,
						startIndex, pageSize);
		eiemsAgencyInformationDao.insertAvgScore();
		//4.封装查询结果并返回
		return new PageObject<>(pageCurrent, pageSize, rowCount, records);
	}
}
